// 业务逻辑中间件
const path = require('path')
const fileUtils = require('../utils/file_utils')
module.exports = async (context, next) => {
  // 根据请求url
  const url = context.request.url
  let fullPath = url.replace('/api', '')
  fullPath = '../data' + fullPath + '.json'
  fullPath = path.join(__dirname, fullPath)
  try {
    const res = await fileUtils.getFileJsonData(fullPath)
    context.response.body = res
  } catch (error) {
    context.response.body = {
      message: error.message,
      status: 404
    }
  }
  await next()
}